﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using BD.Standard.FOM.Program.Utils;
using BD.Standard.YCWH.ProgramParse.Utils;
using Newtonsoft.Json.Linq;

namespace BD.Standard.YCWH.ProgramParse.Forms
{
    internal class Org
    {
        private static readonly string Logpath = @"Org\" + DateTime.Now.ToString("yyyyMM");

        public void PostOrg(DBConnection Con)
        {

            try
            {
                //非必填
                JObject Requestbody = new JObject()
                {
                    {"devId","115458"},
                    {"bizId","18"}
                };
                SignService signService = new SignService();
                string json = Requestbody.ToString();

                var formData = IntegrationUtils.getFormData(json, signService);


                string posturlencoded =
                    new HttpUtils().PosturlencodedAsync("https://api-open-cater.meituan.com/rms/base/v1/auth/resources/get",
                        formData);

                JObject result = JObject.Parse(posturlencoded);

                // ReSharper disable once PossibleNullReferenceException
                if (result["code"].ToString().Equals("OP_SUCCESS"))
                {
                    // ReSharper disable once PossibleNullReferenceException
                    MidTableData.InsertTable("Org", "resources", result["data"].ToString());
                }

                StringBuilder sqlBuilder = new StringBuilder();
                sqlBuilder.AppendLine("update YCWH_Org set inStockType='1,2,3,5,9,10,13',outStockType='1,2,3,5,6,12,13,16' where orgType=1 or orgType=4");
                sqlBuilder.AppendLine("update YCWH_Org set inStockType='1,2,3,4',outStockType='1,2,3,5,7,9' where orgType=5");
                Con.getDataSet(sqlBuilder.ToString());
            }
            catch (Exception e)
            {
                Logger logger = new Logger(ConfigurationManager.AppSettings["log"] + Logpath, DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
                logger.WriteLog("数据出现异常,错误信息：" + e.Message);
                logger.WriteLog("             堆栈信息：" + e.StackTrace);
                Console.WriteLine(e.Message);
            }
        }
           
    }
}